package com.cloudsigns.factorymanager2.engineering.customview;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;

import java.util.List;

/**
 * Created by tony on 2018/3/28.
 */

public class SpinerPopWindow<T> extends PopupWindow {
    private LayoutInflater inflater;
    private ListView mListView;
//    private List<T> dataLs;
//    private MyAdapter mAdapter;

    //    public SpinerPopWindow(Context context, List<T> dataLs, AdapterView.OnItemClickListener clickListener) {
//        super(context);
//        inflater = LayoutInflater.from(context);
//        this.dataLs = dataLs;
//        init(clickListener);
//    }
    public SpinerPopWindow(Context context, AdapterView.OnItemClickListener clickListener) {
        super(context);
        inflater = LayoutInflater.from(context);
        init(clickListener);
    }

    private void init(AdapterView.OnItemClickListener clickListener) {
        View view = inflater.inflate(R.layout.layout_spinner_pop_window, null);
        setContentView(view);
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
//        // 刷新状态
//        this.update();

        setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x00);
        setBackgroundDrawable(dw);

        mListView = (ListView) view.findViewById(R.id.listview);
//        mAdapter = new MyAdapter();
//        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(clickListener);
    }

    public void setAdapter(BaseAdapter adapter) {
        mListView.setAdapter(adapter);
    }


//    private class MyAdapter extends BaseAdapter {
//        @Override
//        public int getCount() {
//            return dataLs.size();
//        }
//
//        @Override
//        public Object getItem(int position) {
//            return dataLs.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            ViewHolder holder = null;
//            if (convertView == null) {
//                holder = new ViewHolder();
//                convertView = inflater.inflate(R.layout.item_spinner_pop_window, null);
//                holder.tvName = (TextView) convertView.findViewById(R.id.tv);
//                convertView.setTag(holder);
//            } else {
//                holder = (ViewHolder) convertView.getTag();
//            }
//
//            holder.tvName.setText(getItem(position).toString());
//            return convertView;
//        }
//    }
//
//    private class ViewHolder {
//        private TextView tvName;
//    }
}
